package com.fker.opt;

import android.util.Log;

public class OptUtil{


    //string 转 Unicode 码
     static String stringToUnicode(String str) {
        StringBuilder stringBuilder = new StringBuilder();
        try {
            char[] unicodeChars = str.toCharArray();

            for (char c : unicodeChars) {
                stringBuilder.append("\\u").append(Integer.toHexString(c | 0x10000).substring(1));
            }
        } catch (Exception e) {

            Log.d(Constants.TAG, "encode is invalid");
        }

        return stringBuilder.toString();

    }

    //Unicode码 string 转
     static String unicodeToString(String unicodeString) {
        StringBuilder source = new StringBuilder();
        try {
            unicodeString = unicodeString.replace("\\u", "");

            for (int i = 0; i < unicodeString.length(); i += 4) {
                String codePoint = unicodeString.substring(i, i + 4);
                source.append((char) Integer.parseInt(codePoint, 16));
            }
        } catch (Exception e) {
            Log.d(Constants.TAG, "decode is invalid");
        }

        return source.toString();

    }
}
